<template>
  <div>
    <city-header></city-header>
    <city-search :cities="cities"></city-search>
    <city-list :cities="cities" :hot="hotCities" :letter="letter"></city-list>
    <city-Alphabet :cities="cities" @change="handleLetterChange"></city-Alphabet>
  </div>
</template>

<script>
import CityHeader from './components/Header'
import CitySearch from './components/Search'
import CityList from './components/List'
import CityAlphabet from './components/Alphabet'
import axios from 'axios'
import {apiUrl, apiUrl2, apiUrl3} from '@/main'

export default {
  name: 'City',
  components: {
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet
  },
  data () {
    return {
      cities: {},
      hotCities: [],
      letter: ''
    }
  },
  methods: {
    getCityInfo () {
      axios.get(apiUrl + '/city.json')
        .then(this.getCityInfoSucc)
        .catch(this.getCityInfoFail)
    },
    getCityInfoSucc (res) {
      res = res.data
      if (res.ret && res.data) {
        const data = res.data
        this.cities = data.cities
        this.hotCities = data.hotCities
      }
    },
    getCityInfoFail (err) {
      console.log(err)
    },
    handleLetterChange (letter) {
      this.letter = letter
    }
  },
  mounted () {
    axios.get(apiUrl2 + '/activity/activityListJson.action?sid=-2&_=1551259430822')
      .then((res) => {
        console.log(res)
      })
    axios.get(apiUrl3 + '/v3/product/category_list?store_id_list=3&class_id=12')
      .then((res) => {
        console.log(res)
      })
    this.getCityInfo()
  }
}
</script>

<style lang="stylus" scoped>
</style>
